import Alamofire

extension APIClient {
    
    // MARK: 登录接口
    func login(params: [String: Any], getResponse:@escaping (_ result: ClientResponseType) -> Void) {
        let requestUrl = APIURL + "User.Login"
        defaultRequest(url: requestUrl, params: params, showMessage: true) { (result) in
            getResponse(result)
        }
    }
    
    // MARK: 注册接口
    func register(params: [String: Any], getResponse:@escaping (_ result: ClientResponseType) -> Void) {
        let requestUrl = APIURL + "User.Register"
        defaultRequest(url: requestUrl, params: params) { (result) in
            getResponse(result)
        }
    }
    
    // MARK: 获取用户信息
    func fetchUserInfo(params: [String: Any], getResponse:@escaping (_ result: ClientResponseType) -> Void) {
        let requestUrl = APIURL + "User.GetUserInfo"
        defaultRequest(url: requestUrl, params: params) { (result) in
            var response = result
            switch result {
            case let .success(info, message):
                let json = info as! JSON
                let userInfo = UserModel(json: json)
                let data = userInfo
                response = .success(data as AnyObject, message)
            default: break
            }
            getResponse(response)
        }
    }
    
    func requestUpdateNickname(params: [String: Any], getResponse:@escaping (_ result: ClientResponseType) -> Void) {
        let requestUrl = APIURL + "User.UpdateNickname"
        defaultRequest(url: requestUrl, params: params) { (result) in
            getResponse(result)
        }
    }
    
    func requestLogout(params: [String: Any], getResponse:@escaping (_ result: ClientResponseType) -> Void) {
        let requestUrl = APIURL + "User.Logout"
        defaultRequest(url: requestUrl, params: params) { (result) in
            getResponse(result)
        }
    }
}
